package com.zonski.jbots.engine.collision;

import com.zonski.jbots.engine.Engine;
import com.zonski.jbots.engine.Entity;
import com.zonski.jbots.engine.CollisionData;
import com.zonski.jbots.engine.CollisionEffect;

/**
 * Implementation of collision effect that proxies another implementation
 * to filter out collisions with entities on the same layer
 */
public final class LayerFilteringCollisionEffectProxy implements CollisionEffect
{
    private CollisionEffect proxied;

    public LayerFilteringCollisionEffectProxy(CollisionEffect proxied)
    {
        this.proxied = proxied;
    }

    public final boolean apply(Entity entity, Engine engine, CollisionData collision)
    {
        boolean result;
        if(entity.layerId == collision.with.layerId)
        {
            result = false;
        }else{
            result = this.proxied.apply(entity, engine, collision);
        }
        return result;
    }

    public final int getCollisionType(Entity entity, Entity with)
    {
        if(entity.layerId != with.layerId)
        {
            return proxied.getCollisionType(entity, with);
        }else{
            return NO_COLLISIONS;
        }
    }
}
